using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
    /// <summary>
    /// Controller class for medianamik_Property
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class PropertyXController
    {
        // Preload our schema..
        PropertyX thisSchemaLoad = new PropertyX();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public PropertyXCollection FetchAll()
        {
            PropertyXCollection coll = new PropertyXCollection();
            Query qry = new Query(PropertyX.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public PropertyXCollection FetchByID(object PropertyId)
        {
            PropertyXCollection coll = new PropertyXCollection().Where("PropertyId", PropertyId).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public PropertyXCollection FetchByQuery(Query qry)
        {
            PropertyXCollection coll = new PropertyXCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object PropertyId)
        {
            return (PropertyX.Delete(PropertyId) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object PropertyId)
        {
            return (PropertyX.Destroy(PropertyId) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(Guid PropertyId,Guid TypeId,string Name,bool IsUnique,string GroupName,Guid DataTypeId,bool IsLanguageNeutral,int? Precision,int? Scale,int? Length,bool AllowNulls,int Flags,Guid WebControlId)
	    {
		    PropertyX item = new PropertyX();
		    
            item.PropertyId = PropertyId;
            
            item.TypeId = TypeId;
            
            item.Name = Name;
            
            item.IsUnique = IsUnique;
            
            item.GroupName = GroupName;
            
            item.DataTypeId = DataTypeId;
            
            item.IsLanguageNeutral = IsLanguageNeutral;
            
            item.Precision = Precision;
            
            item.Scale = Scale;
            
            item.Length = Length;
            
            item.AllowNulls = AllowNulls;
            
            item.Flags = Flags;
            
            item.WebControlId = WebControlId;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(Guid PropertyId,Guid TypeId,string Name,bool IsUnique,string GroupName,Guid DataTypeId,bool IsLanguageNeutral,int? Precision,int? Scale,int? Length,bool AllowNulls,int Flags,Guid WebControlId)
	    {
		    PropertyX item = new PropertyX();
		    
				item.PropertyId = PropertyId;
				
				item.TypeId = TypeId;
				
				item.Name = Name;
				
				item.IsUnique = IsUnique;
				
				item.GroupName = GroupName;
				
				item.DataTypeId = DataTypeId;
				
				item.IsLanguageNeutral = IsLanguageNeutral;
				
				item.Precision = Precision;
				
				item.Scale = Scale;
				
				item.Length = Length;
				
				item.AllowNulls = AllowNulls;
				
				item.Flags = Flags;
				
				item.WebControlId = WebControlId;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

